package com.yinhe.music.yhmusic.adapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.yinhe.music.yhmusic.album.list.AlbumFragment;
import com.yinhe.music.yhmusic.constants.IConstants;
import com.yinhe.music.yhmusic.model.SingerList;
import com.yinhe.music.yhmusic.music.list.MusicListFragment;
import com.yinhe.music.yhmusic.singer.SingerDetailFragment;
import com.yinhe.music.yhmusic.video.list.MvFragment;

import static com.yinhe.music.yhmusic.constants.IConstants.SINGER_DETAIL_ALBUM;
import static com.yinhe.music.yhmusic.constants.IConstants.SINGER_DETAIL_MV;

/**
 * Created by hasee on 2017/3/2.
 */

public class SingerInfoAdapter extends FragmentPagerAdapter {
    private SingerList mSingerInfo;

    public SingerInfoAdapter(FragmentManager fm, SingerList info) {
        super(fm);
        mSingerInfo = info;
    }

    public void update(SingerList info) {
        mSingerInfo = info;
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        switch (position) {
            case 0:
                fragment = MusicListFragment.newInstance(IConstants.SINGER_DETAIL_MUSIC_LIST, mSingerInfo.getSingerId(), null, mSingerInfo.getSongNum());
                break;
            case 1:
                fragment = AlbumFragment.newInstance(SINGER_DETAIL_ALBUM, mSingerInfo.getSingerId(), null);
                break;
            case 2:
                fragment = MvFragment.newInstance(SINGER_DETAIL_MV, mSingerInfo.getSingerId());
                break;
            case 3:
                Bundle bundle = new Bundle();
                bundle.putString("detail", mSingerInfo.getIntro());
                fragment = new SingerDetailFragment();
                fragment.setArguments(bundle);
                break;
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "单曲" + "(" + mSingerInfo.getSongNum() + ")";
            case 1:
                return "专辑" + "(" + mSingerInfo.getAlbumNum() + ")";
            case 2:
                return "MV" + "(" + mSingerInfo.getMovieNum() + ")";
            case 3:
                return "详情";
            default:
                break;
        }
        return null;
    }
}
